//
//  CYMineCapitalCell.m
//  cyjf
//
//  Created by tauCross on 2017/7/7.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYMineCapitalCell.h"



@implementation CYMineCapitalCellObject

@end



@interface CYMineCapitalCell ()

@property(nonatomic, strong)UIButton *withdrawButton;
@property(nonatomic, strong)UIView *line;
@property(nonatomic, strong)UIButton *rechargeButton;

@property(nonatomic, strong)CYMineCapitalCellObject *object;

@end


@implementation CYMineCapitalCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        self.withdrawButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.withdrawButton setTitle:@"提现" forState:UIControlStateNormal];
        [self.withdrawButton setTintColor:HEXCOLOR(@"444444")];
        self.withdrawButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
        [self.withdrawButton addTarget:self action:@selector(onWithdrawButtonTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.withdrawButton];
        
        self.line = [UIView cy_lineWithColor:HEXCOLOR(@"ECECEC")];
        [self.contentView addSubview:self.line];
        
        self.rechargeButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.rechargeButton setTitle:@"充值" forState:UIControlStateNormal];
        [self.rechargeButton setTintColor:APP_DEFAULT_COLOR_RED];
        self.rechargeButton.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
        [self.rechargeButton addTarget:self action:@selector(onRechargeButtonTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.rechargeButton];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 50;
}

- (BOOL)shouldUpdateCellWithObject:(id)object
{
    self.object = object;
    
    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.withdrawButton.width = self.contentView.width / 2;
    self.withdrawButton.height = 50;
    self.withdrawButton.left = 0;
    self.withdrawButton.bottom = self.contentView.height;
    
    self.line.width = 1 / SCREEN_SCALE;
    self.line.height = 22;
    self.line.centerX = self.contentView.width / 2;
    self.line.centerY = self.contentView.height / 2;
    
    self.rechargeButton.frame = self.withdrawButton.frame;
    self.rechargeButton.right = self.contentView.width;

}

#pragma mark - Control Events
- (void)onWithdrawButtonTouchUpInside
{
    if(self.object.withdrawAction)
    {
        self.object.withdrawAction();
    }
}

- (void)onRechargeButtonTouchUpInside
{
    if(self.object.rechargeAction)
    {
        self.object.rechargeAction();
    }
}

@end
